#include "PerspectiveCamera.h"

void PerspectiveCamera::setFov(Double fov) {
	this->fov = fov;
	fovScale = tan(DEG2RAD(fov * 0.5));
}

void PerspectiveCamera::setEyePosition(const Vector3 & eye, const Normal3 & dir, const Normal3 & up) {
	this->eye = eye;
	this->dir = dir;
	this->right = crossProduct(dir, up);
	this->up = crossProduct(right, dir);
}

void PerspectiveCamera::setBlurScale(Double blur) {
	blurScale = blur;
}

void PerspectiveCamera::generateRay(Ray & ray, const Vector2 & pixelSample, const Vector2 & apertureSample) const {
	Vector2 d = pixelSample + apertureSample * blurScale;
	d *= fovScale;
	d.x *= aspectRatio;

	ray.origin = eye;
	ray.dir = d.x * right + d.y * up + dir;
	ray.dir.normalize();
}